home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 4 / BBS in a Box - Macintosh - Volume IV (January 1992) (BBS in a Box).iso / Files / Bus / R / Reversi.cpt / Reversi (.txt)
Encoding:
Wingz Spreadsheet  |  1989-03-17  |  10.2 KB  |  158 lines  |  [WZSS/WNGZ]

  1. WNGZWZSS01b1
  2. Geneva
  3. Geneva
  4. Start Game
  5. Start Game
  6. put -1 into r1c1..r10c10
  7. put 0 into r2c2..r9c9
  8. put 1 into r5c5
  9. put 1 into r6c6
  10. put 2 into r5c6
  11. put 2 into r6c5
  12. repaint object 1
  13. Chicago
  14. Chicago
  15. New Button
  16. New Button
  17. Not a valid move
  18. Computer has no move
  19. therow
  20. thecol
  21. paintone
  22. whosnext
  23. moverank0
  24. setone
  25. computermoveZ
  26. valid
  27. define therow, thecol, paintone, whosnext
  28. on repaint
  29.     define x,y,r,c
  30.     fill bg green()
  31.     if paintone
  32.         line width 20
  33.         case index(r2c2..r9c9, thecol, therow)
  34.             when 0
  35.                 fill pattern 2
  36.                 fill fg white()
  37.                 fill rectangle (thecol * 0.125 + 0.015, therow * 0.125 + 0.015) +(0.095, 0.095)
  38.             when 1
  39.                 fill bg white()
  40.                 paint oval (thecol * 0.125 + 0.015, therow * 0.125 + 0.015) +(0.095, 0.095)
  41.                 frame oval (thecol * 0.125 + 0.015, therow * 0.125 + 0.015) +(0.095, 0.095)
  42.             when 2
  43.                 fill bg black()
  44.                 paint oval (thecol * 0.125 + 0.015, therow * 0.125 + 0.015) +(0.095, 0.095)
  45.         end case
  46.         exit repaint
  47.     end if
  48.     fill pattern 2
  49.     fill fg white()
  50.     paint rectangle (0,0) (1,1)
  51.     fill pattern 20
  52.     fill fg black()
  53.     for x = 0.125 to 0.875 step 0.125
  54.         move (x, 0)
  55.         draw (x, 1)
  56.         move (0, x)
  57.         draw (1, x)
  58.     end for
  59.     line width 20
  60.     for r = 0 to 7
  61.         for c = 0 to 7
  62.             case index(r2c2..r9c9, c, r)
  63.                 when 1
  64.                     fill bg white()
  65.                     paint oval (c * 0.125 + 0.015, r * 0.125 + 0.015) +(0.095, 0.095)
  66.                     frame oval (c * 0.125 + 0.015, r * 0.125 + 0.015) +(0.095, 0.095)
  67.                 when 2
  68.                     fill bg black()
  69.                     paint oval (c * 0.125 + 0.015, r * 0.125 + 0.015) +(0.095, 0.095)
  70.             end case
  71.         end for
  72.     end for
  73. end repaint
  74. on mouseup
  75.     define xpos,ypos
  76.     xpos = int(mousex() / controlwidth() * 8)
  77.     ypos = int(8 - mousey() / controlheight() * 8)
  78.     if not whosnext
  79.         whosnext = 1
  80.     end if
  81.     if moverank(xpos, ypos, whosnext, TRUE())
  82.         call setone(xpos, ypos, whosnext)
  83.         whosnext = if(whosnext=1,2,1)
  84.         call computermove()
  85.     else
  86.         message "Not a valid move"
  87.     end if
  88. end mouseup
  89. function setone(col, row, value)
  90.     put value into makecell(col + 2, row + 2)
  91.     paintone = TRUE()
  92.     therow = row
  93.     thecol = col
  94.     repaint object 1
  95.     paintone = FALSE()
  96. end function
  97. function valid(col, row, coloff, rowoff, who, doit)
  98.     define tmp, count, ret, savecol, saverow
  99.     if not index(r2c2..r9c9, col, row)
  100.         tmp = index(r2c2..r9c9, col + coloff, row + rowoff)
  101.         if tmp > 0 and tmp <> who
  102.             count = 1
  103.             savecol = col
  104.             saverow = row
  105.             col = col + coloff
  106.             row = row + rowoff
  107.             while tmp = index(r2c2..r9c9, col + coloff, row + rowoff)
  108.                 count = count + 1
  109.                 col = col + coloff
  110.                 row = row + rowoff
  111.             end while
  112.             if who = index(r2c2..r9c9, col + coloff, row + rowoff)
  113.                 ret = count + index(m2..t9, savecol, saverow) + rand()
  114.                 if doit
  115.                     while savecol <> col or saverow <> row
  116.                         call setone(col, row, who)
  117.                         col = col - coloff
  118.                         row = row - rowoff
  119.                     end while
  120.                 end if
  121.             end if
  122.         end if
  123.     end if
  124.     return ret
  125. end function
  126. function moverank(col, row, who, doit)
  127.     return     valid(col, row, -1, -1, who, doit) +
  128.             valid(col, row, -1,  0, who, doit) +
  129.             valid(col, row, -1,  1, who, doit) +
  130.             valid(col, row,  0, -1, who, doit) +
  131.             valid(col, row,  0,  1, who, doit) +
  132.             valid(col, row,  1, -1, who, doit) +
  133.             valid(col, row,  1,  0, who, doit) +
  134.             valid(col, row,  1,  1, who, doit)
  135. end function
  136. function computermove()
  137.     define r, c, foundr, foundc, high, tmp
  138.     for r = 0 to 7
  139.         for c = 0 to 7
  140.             tmp = moverank(c, r, whosnext, FALSE())
  141.             if tmp > high
  142.                 high = tmp
  143.                 foundr = r
  144.                 foundc = c
  145.             end if
  146.         end for
  147.     end for
  148.     if high
  149.         call moverank(foundc, foundr, whosnext, TRUE())
  150.         call setone(foundc, foundr, whosnext)
  151.     else
  152.         message "Computer has no move"
  153.     end if
  154.     whosnext = if(whosnext=1,2,1)
  155. end function
  156. Chicago
  157. Chicago
  158.